using System;
using System.Linq;
using System.Collections.Generic;

using DemoApp.DataAccess;

using EntModApp.EntServices.Business;
using EntModApp.EntServices.Data;

namespace DemoApp.BusinessLayer 
{
  public partial class SecurableActionObjectRepository : 
    ISecurableActionObjectRepository 
  {
    public IBusinessObjectCollection<ISecurableAction> RetrieveAll()
    {
      var query = new SecurableActionLoadSettings();
      return Retrieve(query);
    }

    public IBusinessObjectCollection<ISecurableAction> Retrieve(SecurableActionLoadSettings query)
    {
      query = SecurableActionLoadSettings.FromSecurableActionLoadSettings(query);
      if (query.AsReadonly)
      {
        var result = CslaSecurableActionInfoCollection.GetSecurableActionInfoCollection(query);
        return result;
      }
      else
      {
        var result = CslaSecurableActionEditCollection.GetSecurableActionEditCollection(query);
        return result;
      }
    }

    public ISecurableAction RetrieveOne(SecurableActionLoadSettings query)
    {
      query = SecurableActionLoadSettings.FromSecurableActionLoadSettings(query);
      if (query.AsReadonly)
      {
        var result = CslaSecurableActionInfoCollection.GetSecurableActionInfoCollection(query);
        return result.FirstOrDefault<ISecurableAction>();
      }
      else
      {
        var result = CslaSecurableActionEditCollection.GetSecurableActionEditCollection(query);
        return result.FirstOrDefault<ISecurableAction>();
      }
    }

    public int Count()
    {
      return Count(null);
    }

    public int Count(SecurableActionLoadSettings query)
    {
      query = SecurableActionLoadSettings.FromSecurableActionLoadSettings(query);
      return CslaSecurableActionInfoCollection.GetCount(query);
    }

    public ISecurableAction New()
    {
      return CslaSecurableActionEdit.New();
    }

    public void Save(IBusinessObjectCollection<ISecurableAction> collection)
    {
      throw new NotImplementedException();
    }

    public void Save(ISecurableAction obj)
    {
      throw new NotImplementedException();
    }
  }
}
